package org.ricks.boot;

import org.ricks.boot.exception.ServerBootstrapException;
import org.ricks.ioc.Lifecycle;
import org.ricks.ioc.RicksContext;
import java.util.Arrays;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 服务启动类
 */
public interface ServerBootstrap extends Lifecycle {

    default void startBefore () {
        Scan scan = this.getClass().getAnnotation(Scan.class);
        if (Objects.isNull(scan))
            throw new ServerBootstrapException("Bootstrap启动之前必须配置扫描项目包路径，不然无法正常加载配置文件 & 初始化IOC容器 ！");
        String[] packagesStr = scan.value();
        Set<String> scanPackages = Arrays.stream(packagesStr).collect(Collectors.toSet());
        RicksContext.me().scan(scanPackages);
        RicksContext.me().init();
    }
}
